package com.itrus.util;

import com.itrus.cert.CertNames;
import com.itrus.cert.Names;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Principal;
import java.security.Security;
import java.security.UnrecoverableKeyException;
import java.security.cert.CRLException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509CRL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.security.auth.x500.X500Principal;
import org.apache.commons.lang.StringUtils;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.DEREncodable;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.x509.CRLDistPoint;
import org.bouncycastle.asn1.x509.DistributionPoint;
import org.bouncycastle.asn1.x509.DistributionPointName;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.X509DefaultEntryConverter;
import org.bouncycastle.asn1.x509.X509Extensions;
import org.bouncycastle.asn1.x509.X509NameEntryConverter;
import org.bouncycastle.asn1.x509.X509NameTokenizer;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.x509.extension.X509ExtensionUtil;

public class CertUtils
{
  static
  {
    if (Security.getProvider("BC") == null)
      Security.addProvider(new BouncyCastleProvider());
  }

  public static void JKSToPKCS12(String paramString1, char[] paramArrayOfChar1, String paramString2, char[] paramArrayOfChar2, String paramString3, char[] paramArrayOfChar3)
    throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException
  {
    KeyStore localKeyStore1 = KeyStore.getInstance("JKS");
    FileInputStream localFileInputStream = new FileInputStream(paramString1);
    localKeyStore1.load(localFileInputStream, paramArrayOfChar1);
    localFileInputStream.close();
    KeyStore localKeyStore2 = KeyStore.getInstance("PKCS12");
    localKeyStore2.load(null, paramArrayOfChar3);
    Enumeration localEnumeration = localKeyStore1.aliases();
    while (true)
    {
      if (!localEnumeration.hasMoreElements())
      {
        FileOutputStream localFileOutputStream = new FileOutputStream(paramString3);
        localKeyStore2.store(localFileOutputStream, paramArrayOfChar3);
        localFileOutputStream.close();
        return;
      }
      String str = (String)localEnumeration.nextElement();
      if ((localKeyStore1.isKeyEntry(str)) && (str.equals(paramString2)))
        localKeyStore2.setKeyEntry(paramString2, localKeyStore1.getKey(str, paramArrayOfChar2), paramArrayOfChar3, localKeyStore1.getCertificateChain(str));
    }
  }

  public static void PKCS12ToJKS(String paramString1, char[] paramArrayOfChar1, String paramString2, char[] paramArrayOfChar2)
    throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException
  {
    KeyStore localKeyStore1 = KeyStore.getInstance("PKCS12");
    FileInputStream localFileInputStream = new FileInputStream(paramString1);
    localKeyStore1.load(localFileInputStream, paramArrayOfChar1);
    localFileInputStream.close();
    KeyStore localKeyStore2 = KeyStore.getInstance("JKS");
    localKeyStore2.load(null, paramArrayOfChar2);
    Enumeration localEnumeration = localKeyStore1.aliases();
    String str1;
    do
    {
      if (!localEnumeration.hasMoreElements())
      {
        FileOutputStream localFileOutputStream = new FileOutputStream(paramString2);
        localKeyStore2.store(localFileOutputStream, paramArrayOfChar2);
        localFileOutputStream.close();
        return;
      }
      str1 = (String)localEnumeration.nextElement();
    }
    while (!localKeyStore1.isKeyEntry(str1));
    Key localKey = localKeyStore1.getKey(str1, paramArrayOfChar1);
    Certificate[] arrayOfCertificate = localKeyStore1.getCertificateChain(str1);
    Names localNames1 = com.itrus.cert.X509Certificate.getInstance((java.security.cert.X509Certificate)arrayOfCertificate[0]).getSubjectNames();
    if (localNames1.getItem("CN") != null);
    int i;
    for (String str2 = localNames1.getItem("CN"); ; str2 = (String)localNames1.getItems((String)localNames1.keys().nextElement()).elementAt(0))
    {
      localKeyStore2.setKeyEntry(str2, localKey, paramArrayOfChar2, arrayOfCertificate);
      for (i = 0; i < arrayOfCertificate.length; i++)
        if (i != 0)
          break label224;
      break;
    }
    label224: Names localNames2 = com.itrus.cert.X509Certificate.getInstance((java.security.cert.X509Certificate)arrayOfCertificate[i]).getSubjectNames();
    if (localNames2.getItem("CN") != null);
    for (String str3 = localNames2.getItem("CN"); ; str3 = (String)localNames2.getItems((String)localNames2.keys().nextElement()).elementAt(0))
    {
      localKeyStore2.setCertificateEntry(str3, arrayOfCertificate[i]);
      break;
    }
  }

  public static String X509CertificateToPEM(java.security.cert.X509Certificate paramX509Certificate)
    throws CertificateEncodingException
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("-----BEGIN CERTIFICATE-----\n");
    localStringBuffer.append(new String(Base64.encode(paramX509Certificate.getEncoded(), true)));
    localStringBuffer.append("\n-----END CERTIFICATE-----");
    return localStringBuffer.toString();
  }

  public static java.security.cert.X509Certificate changeProvider(java.security.cert.X509Certificate paramX509Certificate, String paramString)
    throws CertificateException, NoSuchProviderException
  {
    if (paramString == null);
    for (CertificateFactory localCertificateFactory = CertificateFactory.getInstance("X.509"); ; localCertificateFactory = CertificateFactory.getInstance("X.509", paramString))
      return (java.security.cert.X509Certificate)localCertificateFactory.generateCertificate(new ByteArrayInputStream(paramX509Certificate.getEncoded()));
  }

  public static String getAlias(String paramString)
  {
    CertNames localCertNames = parseCertDistinguishName(paramString, null);
    String str = localCertNames.getItem("CN");
    if (str == null)
    {
      Iterator localIterator = localCertNames.keySet().iterator();
      if (localIterator.hasNext())
        str = (String)localCertNames.getItems((String)localIterator.next()).get(0);
    }
    return str;
  }

  public static String getCRLDistributionPointURL(java.security.cert.X509Certificate paramX509Certificate)
    throws IOException
  {
    String str = null;
    byte[] arrayOfByte = paramX509Certificate.getExtensionValue(X509Extensions.CRLDistributionPoints.getId());
    if (arrayOfByte == null)
      return null;
    DistributionPoint[] arrayOfDistributionPoint = CRLDistPoint.getInstance(X509ExtensionUtil.fromExtensionValue(arrayOfByte)).getDistributionPoints();
    int i = 0;
    if (i >= arrayOfDistributionPoint.length)
      return str;
    GeneralName[] arrayOfGeneralName = ((GeneralNames)arrayOfDistributionPoint[i].getDistributionPoint().getName()).getNames();
    DEREncodable localDEREncodable = arrayOfGeneralName[0].getName();
    switch (arrayOfGeneralName[0].getTagNo())
    {
    case 4:
    case 5:
    default:
      System.out.println("不可识别的CRLDistributionPoint，TagNo=" + arrayOfGeneralName[0].getTagNo());
    case 2:
    case 6:
    case 3:
    }
    while (true)
    {
      i++;
      break;
      System.out.println("本函数不支持dNSName");
      continue;
      str = DERIA5String.getInstance(localDEREncodable).getString();
      continue;
      X509Principal localX509Principal = new X509Principal(((DERSequence)localDEREncodable).getEncoded());
      System.out.println("本函数不支持LDAP，x400Address=" + localX509Principal.getName());
    }
  }

  public static String getCertID(java.security.cert.X509Certificate paramX509Certificate)
  {
    try
    {
      String str = CipherUtils.sha1(paramX509Certificate.getEncoded()).toUpperCase();
      return str;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  public static CertificateFactory getCertificateFactory()
  {
    try
    {
      CertificateFactory localCertificateFactory = CertificateFactory.getInstance("X.509", "BC");
      return localCertificateFactory;
    }
    catch (CertificateException localCertificateException)
    {
      return null;
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      label11: break label11;
    }
  }

  private static String getDN(java.security.cert.X509Certificate paramX509Certificate, int paramInt)
  {
    if (paramX509Certificate == null)
      return null;
    try
    {
      java.security.cert.X509Certificate localX509Certificate = (java.security.cert.X509Certificate)getCertificateFactory().generateCertificate(new ByteArrayInputStream(paramX509Certificate.getEncoded()));
      String str1;
      if (paramInt == 1)
        str1 = localX509Certificate.getSubjectDN().toString();
      String str2;
      for (Object localObject = str1; ; localObject = str2)
      {
        return stringToBCDNString((String)localObject);
        str2 = localX509Certificate.getIssuerDN().toString();
      }
    }
    catch (CertificateException localCertificateException)
    {
    }
    return null;
  }

  private static Vector getDefaultX509FieldOrder()
  {
    Vector localVector = new Vector();
    String[] arrayOfString = DnComponents.getDnObjects();
    for (int i = 0; ; i++)
    {
      if (i >= arrayOfString.length)
        return localVector;
      localVector.add(DnComponents.getOid(arrayOfString[i]));
    }
  }

  public static byte[] getExtensionValue(java.security.cert.X509Certificate paramX509Certificate, String paramString)
  {
    byte[] arrayOfByte1 = paramX509Certificate.getExtensionValue(paramString);
    if (arrayOfByte1 != null)
    {
      byte[] arrayOfByte2 = new byte[-2 + arrayOfByte1.length];
      System.arraycopy(arrayOfByte1, 2, arrayOfByte2, 0, -2 + arrayOfByte1.length);
      return arrayOfByte2;
    }
    return null;
  }

  public static String getICAValidSerialNumber(String paramString)
  {
    if (paramString == null)
      return null;
    if (paramString.length() % 2 == 1)
      paramString = "0" + paramString;
    if (paramString.startsWith("00"))
      return paramString.substring(2).toUpperCase();
    return paramString.toUpperCase();
  }

  public static String getIEValidSerialNumber(String paramString)
  {
    if (paramString == null)
      paramString = null;
    while (true)
    {
      return paramString;
      if (paramString.length() != 0)
      {
        paramString = paramString.toLowerCase();
        if (paramString.length() % 2 == 1)
          paramString = "0" + paramString;
        String str = paramString.substring(0, 1);
        try
        {
          int i = Integer.parseInt(str, 16);
          if (i >= 8)
            return "00" + paramString;
        }
        catch (Exception localException)
        {
        }
      }
    }
    return paramString;
  }

  public static IssuerAndSerialNumber getIssuerAndSerialNumber(java.security.cert.X509Certificate paramX509Certificate)
  {
    ASN1InputStream localASN1InputStream = new ASN1InputStream(paramX509Certificate.getIssuerX500Principal().getEncoded());
    try
    {
      IssuerAndSerialNumber localIssuerAndSerialNumber = new IssuerAndSerialNumber(org.bouncycastle.asn1.x509.X509Name.getInstance((DERSequence)localASN1InputStream.readObject()), paramX509Certificate.getSerialNumber());
      return localIssuerAndSerialNumber;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  public static String getIssuerDN(java.security.cert.X509Certificate paramX509Certificate)
  {
    return getDN(paramX509Certificate, 2);
  }

  public static Names getIssuerNames(java.security.cert.X509Certificate paramX509Certificate)
  {
    return parseDistinguishName(paramX509Certificate.getIssuerDN().getName(), null);
  }

  public static Names getIssuerNames(java.security.cert.X509Certificate paramX509Certificate, String paramString)
  {
    return parseDistinguishName(paramX509Certificate.getIssuerDN().getName(), paramString);
  }

  private static com.itrus.cert.X509Name getOrderedX509Name(com.itrus.cert.X509Name paramX509Name, Vector paramVector, X509NameEntryConverter paramX509NameEntryConverter)
  {
    if (paramVector == null)
      paramVector = new Vector();
    Vector localVector1 = new Vector();
    Vector localVector2 = new Vector();
    Hashtable localHashtable = new Hashtable();
    Iterator localIterator1 = paramVector.iterator();
    Vector localVector4;
    int i;
    while (true)
      if (!localIterator1.hasNext())
      {
        localVector4 = paramX509Name.getOIDs();
        i = 0;
        if (i >= localVector4.size())
          return new com.itrus.cert.X509Name(localVector1, localVector2, paramX509NameEntryConverter);
      }
      else
      {
        DERObjectIdentifier localDERObjectIdentifier1 = (DERObjectIdentifier)localIterator1.next();
        if (localHashtable.containsKey(localDERObjectIdentifier1))
          continue;
        Vector localVector3 = getX509NameFields(paramX509Name, localDERObjectIdentifier1);
        if (localVector3 == null)
          continue;
        Iterator localIterator2 = localVector3.iterator();
        while (localIterator2.hasNext())
        {
          Object localObject1 = localIterator2.next();
          localHashtable.put(localDERObjectIdentifier1, localObject1);
          localVector1.add(localDERObjectIdentifier1);
          localVector2.add(localObject1);
        }
      }
    DERObjectIdentifier localDERObjectIdentifier2 = (DERObjectIdentifier)localVector4.get(i);
    if (localHashtable.containsKey(localDERObjectIdentifier2));
    while (true)
    {
      i++;
      break;
      Vector localVector5 = getX509NameFields(paramX509Name, localDERObjectIdentifier2);
      if (localVector5 != null)
      {
        Iterator localIterator3 = localVector5.iterator();
        while (localIterator3.hasNext())
        {
          Object localObject2 = localIterator3.next();
          localHashtable.put(localDERObjectIdentifier2, localObject2);
          localVector1.add(localDERObjectIdentifier2);
          localVector2.add(localObject2);
          new StringBuffer().append("added --> ").append(localDERObjectIdentifier2).append(" val: ").append(localObject2).toString();
        }
      }
    }
  }

  public static String getPartFromDN(String paramString1, String paramString2)
  {
    String str1;
    X509NameTokenizer localX509NameTokenizer;
    if ((paramString1 != null) && (paramString2 != null))
    {
      str1 = paramString2 + "=";
      localX509NameTokenizer = new X509NameTokenizer(paramString1);
    }
    String str2;
    do
    {
      if (!localX509NameTokenizer.hasMoreTokens())
        return null;
      str2 = localX509NameTokenizer.nextToken();
    }
    while ((str2.length() <= str1.length()) || (!str2.substring(0, str1.length()).equalsIgnoreCase(str1)));
    return str2.substring(str1.length());
  }

  public static ArrayList getPartsFromDN(String paramString1, String paramString2)
  {
    ArrayList localArrayList = new ArrayList();
    String str1;
    X509NameTokenizer localX509NameTokenizer;
    if ((paramString1 != null) && (paramString2 != null))
    {
      str1 = paramString2 + "=";
      localX509NameTokenizer = new X509NameTokenizer(paramString1);
    }
    while (true)
    {
      if (!localX509NameTokenizer.hasMoreTokens())
        return localArrayList;
      String str2 = localX509NameTokenizer.nextToken();
      if ((str2.length() > str1.length()) && (str2.substring(0, str1.length()).equalsIgnoreCase(str1)))
        localArrayList.add(str2.substring(str1.length()));
    }
  }

  public static String getSubjectDN(java.security.cert.X509Certificate paramX509Certificate)
  {
    return getDN(paramX509Certificate, 1);
  }

  public static Names getSubjectNames(java.security.cert.X509Certificate paramX509Certificate)
  {
    return parseDistinguishName(paramX509Certificate.getSubjectDN().getName(), null);
  }

  public static Names getSubjectNames(java.security.cert.X509Certificate paramX509Certificate, String paramString)
  {
    return parseDistinguishName(paramX509Certificate.getSubjectDN().getName(), paramString);
  }

  public static X509CRL getX509CRLFromBytes(byte[] paramArrayOfByte, String paramString)
    throws CertificateException, NoSuchProviderException, CRLException
  {
    if (paramString == null);
    for (CertificateFactory localCertificateFactory = CertificateFactory.getInstance("X.509"); ; localCertificateFactory = CertificateFactory.getInstance("X.509", paramString))
      return (X509CRL)localCertificateFactory.generateCRL(new ByteArrayInputStream(paramArrayOfByte));
  }

  public static java.security.cert.X509Certificate getX509CertificateFromBase64(String paramString)
    throws CertificateException
  {
    if (paramString == null)
      return null;
    byte[] arrayOfByte = Base64.decode(paramString);
    return (java.security.cert.X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(arrayOfByte));
  }

  public static java.security.cert.X509Certificate getX509CertificateFromBytes(byte[] paramArrayOfByte)
    throws CertificateException
  {
    if (paramArrayOfByte == null)
      return null;
    return (java.security.cert.X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(paramArrayOfByte));
  }

  public static java.security.cert.X509Certificate getX509CertificateFromFile(String paramString)
    throws CertificateException, IOException
  {
    if (paramString == null)
      return null;
    FileInputStream localFileInputStream = new FileInputStream(paramString);
    java.security.cert.X509Certificate localX509Certificate = (java.security.cert.X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(localFileInputStream);
    localFileInputStream.close();
    return localX509Certificate;
  }

  private static Vector getX509NameFields(com.itrus.cert.X509Name paramX509Name, DERObjectIdentifier paramDERObjectIdentifier)
  {
    Vector localVector1 = paramX509Name.getOIDs();
    Vector localVector2 = paramX509Name.getValues();
    Vector localVector3 = null;
    int i = 0;
    if (i >= localVector1.size())
      return localVector3;
    if (!paramDERObjectIdentifier.equals(localVector1.elementAt(i)));
    while (true)
    {
      i++;
      break;
      if (localVector3 == null)
        localVector3 = new Vector();
      localVector3.add(localVector2.get(i));
    }
  }

  public static String getX509NameString(X500Principal paramX500Principal)
  {
    return getX509NameString(paramX500Principal.getEncoded());
  }

  public static String getX509NameString(byte[] paramArrayOfByte)
  {
    ASN1InputStream localASN1InputStream = new ASN1InputStream(paramArrayOfByte);
    try
    {
      String str = com.itrus.cert.X509Name.getInstance((DERSequence)localASN1InputStream.readObject()).toString();
      return str;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  protected static boolean isDNReversed(String paramString)
  {
    boolean bool1 = false;
    X509NameTokenizer localX509NameTokenizer;
    String str2;
    String[] arrayOfString;
    String str3;
    String str4;
    int i;
    int j;
    if (paramString != null)
    {
      localX509NameTokenizer = new X509NameTokenizer(paramString);
      boolean bool2 = localX509NameTokenizer.hasMoreTokens();
      String str1 = null;
      str2 = null;
      if (bool2)
        str1 = localX509NameTokenizer.nextToken();
      if (localX509NameTokenizer.hasMoreTokens())
        break label122;
      arrayOfString = DnComponents.getDnObjects();
      bool1 = false;
      if (str1 != null)
      {
        bool1 = false;
        if (str2 != null)
        {
          str3 = str1.substring(0, str1.indexOf('='));
          str4 = str2.substring(0, str2.indexOf('='));
          i = 0;
          j = 0;
        }
      }
    }
    for (int k = 0; ; k++)
    {
      if (k >= arrayOfString.length)
      {
        bool1 = false;
        if (j < i)
          bool1 = true;
        return bool1;
        label122: str2 = localX509NameTokenizer.nextToken();
        break;
      }
      if (str3.toLowerCase().equals(arrayOfString[k]))
        i = k;
      if (str4.toLowerCase().equals(arrayOfString[k]))
        j = k;
    }
  }

  public static boolean isOnValidPeriod(java.security.cert.X509Certificate paramX509Certificate)
  {
    Date localDate1 = paramX509Certificate.getNotBefore();
    Date localDate2 = paramX509Certificate.getNotAfter();
    Date localDate3 = new Date();
    return (!localDate3.before(localDate1)) && (!localDate3.after(localDate2));
  }

  public static boolean isSelfSigned(java.security.cert.X509Certificate paramX509Certificate)
  {
    new StringBuffer().append(">isSelfSigned: cert: ").append(getIssuerDN(paramX509Certificate)).append("\n").append(getSubjectDN(paramX509Certificate)).toString();
    boolean bool = getSubjectDN(paramX509Certificate).equals(getIssuerDN(paramX509Certificate));
    new StringBuffer().append("<isSelfSigned:").append(bool).toString();
    return bool;
  }

  public static boolean isValid(java.security.cert.X509Certificate paramX509Certificate)
  {
    return isOnValidPeriod(paramX509Certificate);
  }

  // ERROR //
  public static com.itrus.cert.PKCS10CertificationRequest loadCSR(String paramString)
    throws com.itrus.cryptorole.CryptoException, IOException
  {
    // Byte code:
    //   0: new 590	org/bouncycastle/openssl/PEMReader
    //   3: dup
    //   4: new 592	java/io/InputStreamReader
    //   7: dup
    //   8: new 46	java/io/FileInputStream
    //   11: dup
    //   12: new 594	java/io/File
    //   15: dup
    //   16: aload_0
    //   17: invokespecial 595	java/io/File:<init>	(Ljava/lang/String;)V
    //   20: invokespecial 598	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   23: invokespecial 601	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;)V
    //   26: invokespecial 604	org/bouncycastle/openssl/PEMReader:<init>	(Ljava/io/Reader;)V
    //   29: astore_1
    //   30: new 606	com/itrus/cert/PKCS10CertificationRequest
    //   33: dup
    //   34: aload_1
    //   35: invokevirtual 608	org/bouncycastle/openssl/PEMReader:readObject	()Ljava/lang/Object;
    //   38: checkcast 610	org/bouncycastle/jce/PKCS10CertificationRequest
    //   41: invokevirtual 611	org/bouncycastle/jce/PKCS10CertificationRequest:getEncoded	()[B
    //   44: invokespecial 612	com/itrus/cert/PKCS10CertificationRequest:<init>	([B)V
    //   47: astore_2
    //   48: aload_2
    //   49: invokevirtual 615	com/itrus/cert/PKCS10CertificationRequest:verify	()Z
    //   52: ifne +38 -> 90
    //   55: new 584	com/itrus/cryptorole/CryptoException
    //   58: dup
    //   59: ldc_w 617
    //   62: invokespecial 618	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;)V
    //   65: athrow
    //   66: astore 6
    //   68: new 584	com/itrus/cryptorole/CryptoException
    //   71: dup
    //   72: ldc_w 620
    //   75: aload 6
    //   77: invokespecial 623	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   80: athrow
    //   81: astore 4
    //   83: aload_1
    //   84: invokevirtual 624	org/bouncycastle/openssl/PEMReader:close	()V
    //   87: aload 4
    //   89: athrow
    //   90: aload_1
    //   91: invokevirtual 624	org/bouncycastle/openssl/PEMReader:close	()V
    //   94: aload_2
    //   95: areturn
    //   96: astore_3
    //   97: new 584	com/itrus/cryptorole/CryptoException
    //   100: dup
    //   101: ldc_w 620
    //   104: aload_3
    //   105: invokespecial 623	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   108: athrow
    //   109: astore 7
    //   111: aload_2
    //   112: areturn
    //   113: astore 5
    //   115: goto -28 -> 87
    //
    // Exception table:
    //   from	to	target	type
    //   30	66	66	java/lang/ClassCastException
    //   30	66	81	finally
    //   68	81	81	finally
    //   97	109	81	finally
    //   30	66	96	java/security/GeneralSecurityException
    //   90	94	109	java/io/IOException
    //   83	87	113	java/io/IOException
  }

  // ERROR //
  public static com.itrus.cert.PKCS10CertificationRequest loadCSRString(String paramString)
    throws com.itrus.cryptorole.CryptoException, IOException
  {
    // Byte code:
    //   0: new 590	org/bouncycastle/openssl/PEMReader
    //   3: dup
    //   4: new 627	java/io/CharArrayReader
    //   7: dup
    //   8: aload_0
    //   9: invokevirtual 631	java/lang/String:toCharArray	()[C
    //   12: invokespecial 634	java/io/CharArrayReader:<init>	([C)V
    //   15: invokespecial 604	org/bouncycastle/openssl/PEMReader:<init>	(Ljava/io/Reader;)V
    //   18: astore_1
    //   19: new 606	com/itrus/cert/PKCS10CertificationRequest
    //   22: dup
    //   23: aload_1
    //   24: invokevirtual 608	org/bouncycastle/openssl/PEMReader:readObject	()Ljava/lang/Object;
    //   27: checkcast 610	org/bouncycastle/jce/PKCS10CertificationRequest
    //   30: invokevirtual 611	org/bouncycastle/jce/PKCS10CertificationRequest:getEncoded	()[B
    //   33: invokespecial 612	com/itrus/cert/PKCS10CertificationRequest:<init>	([B)V
    //   36: astore_2
    //   37: aload_2
    //   38: invokevirtual 615	com/itrus/cert/PKCS10CertificationRequest:verify	()Z
    //   41: ifne +38 -> 79
    //   44: new 584	com/itrus/cryptorole/CryptoException
    //   47: dup
    //   48: ldc_w 617
    //   51: invokespecial 618	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;)V
    //   54: athrow
    //   55: astore 6
    //   57: new 584	com/itrus/cryptorole/CryptoException
    //   60: dup
    //   61: ldc_w 620
    //   64: aload 6
    //   66: invokespecial 623	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   69: athrow
    //   70: astore 4
    //   72: aload_1
    //   73: invokevirtual 624	org/bouncycastle/openssl/PEMReader:close	()V
    //   76: aload 4
    //   78: athrow
    //   79: aload_1
    //   80: invokevirtual 624	org/bouncycastle/openssl/PEMReader:close	()V
    //   83: aload_2
    //   84: areturn
    //   85: astore_3
    //   86: new 584	com/itrus/cryptorole/CryptoException
    //   89: dup
    //   90: ldc_w 620
    //   93: aload_3
    //   94: invokespecial 623	com/itrus/cryptorole/CryptoException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   97: athrow
    //   98: astore 7
    //   100: aload_2
    //   101: areturn
    //   102: astore 5
    //   104: goto -28 -> 76
    //
    // Exception table:
    //   from	to	target	type
    //   19	55	55	java/lang/ClassCastException
    //   19	55	70	finally
    //   57	70	70	finally
    //   86	98	70	finally
    //   19	55	85	java/security/GeneralSecurityException
    //   79	83	98	java/io/IOException
    //   72	76	102	java/io/IOException
  }

  public static CertNames parseCertDistinguishName(String paramString1, String paramString2)
  {
    String str1 = ", ";
    if ((paramString2 != null) && (paramString2.equals("BC")))
      str1 = ",";
    CertNames localCertNames = new CertNames();
    String[] arrayOfString = paramString1.split(str1);
    String str2 = "";
    int i = -1 + arrayOfString.length;
    if (i < 0)
      return localCertNames;
    if (!str2.equals(""));
    int j;
    for (String str3 = arrayOfString[i] + str2; ; str3 = arrayOfString[i])
    {
      j = str3.indexOf("=");
      if (-1 != j)
        break label144;
      str2 = str1 + str3;
      i--;
      break;
    }
    label144: String str4 = str3.substring(0, j);
    String str5 = str3.substring(j + 1, str3.length());
    if ((str5.indexOf("\"") == 0) && (-1 + str5.length() == str5.lastIndexOf("\"")))
    {
      String str6 = str5.substring(1, str5.length());
      str5 = str6.substring(0, -1 + str6.length());
    }
    if (localCertNames.containsKey(str4))
      ((Vector)localCertNames.get(str4)).add(str5);
    while (true)
    {
      str2 = "";
      break;
      Vector localVector = new Vector();
      localVector.add(str5);
      localCertNames.put(str4, localVector);
    }
  }

  public static Names parseDistinguishName(String paramString1, String paramString2)
  {
    String str1 = ", ";
    if ((paramString2 != null) && (paramString2.equals("BC")))
      str1 = ",";
    Names localNames = new Names();
    String[] arrayOfString = paramString1.split(str1);
    String str2 = "";
    int i = -1 + arrayOfString.length;
    if (i < 0)
      return localNames;
    if (!str2.equals(""));
    int j;
    for (String str3 = arrayOfString[i] + str2; ; str3 = arrayOfString[i])
    {
      j = str3.indexOf("=");
      if (-1 != j)
        break label144;
      str2 = str1 + str3;
      i--;
      break;
    }
    label144: String str4 = str3.substring(0, j);
    String str5 = str3.substring(j + 1, str3.length());
    if ((str5.indexOf("\"") == 0) && (-1 + str5.length() == str5.lastIndexOf("\"")))
    {
      String str6 = str5.substring(1, str5.length());
      str5 = str6.substring(0, -1 + str6.length());
    }
    if (localNames.containsKey(str4))
      ((Vector)localNames.get(str4)).add(str5);
    while (true)
    {
      str2 = "";
      break;
      Vector localVector = new Vector();
      localVector.add(str5);
      localNames.put(str4, localVector);
    }
  }

  public static String reverseDN(String paramString)
  {
    String str1 = null;
    BasicX509NameTokenizer localBasicX509NameTokenizer;
    StringBuffer localStringBuffer;
    int i;
    if (paramString != null)
    {
      localBasicX509NameTokenizer = new BasicX509NameTokenizer(paramString);
      localStringBuffer = new StringBuffer();
      i = 1;
      if (localBasicX509NameTokenizer.hasMoreTokens())
        break label53;
      int j = localStringBuffer.length();
      str1 = null;
      if (j > 0)
        str1 = localStringBuffer.toString();
    }
    return str1;
    label53: String str2 = localBasicX509NameTokenizer.nextToken();
    if (i == 0)
      localStringBuffer.insert(0, ",");
    while (true)
    {
      localStringBuffer.insert(0, str2);
      break;
      i = 0;
    }
  }

  public static String stringToBCDNString(String paramString)
  {
    if (isDNReversed(paramString))
      paramString = reverseDN(paramString);
    com.itrus.cert.X509Name localX509Name = stringToBcX509Name(paramString);
    String str = null;
    if (localX509Name != null)
      str = localX509Name.toString();
    if ((str != null) && (str.length() > 250))
      new StringBuffer().append("Warning! DN is more than 250 characters long. Some databases have only 250 characters in the database for SubjectDN. Clipping may occur! DN (").append(str.length()).append(" chars): ").append(str).toString();
    return str;
  }

  public static com.itrus.cert.X509Name stringToBcX509Name(String paramString)
  {
    return stringToBcX509Name(paramString, new X509DefaultEntryConverter());
  }

  private static com.itrus.cert.X509Name stringToBcX509Name(String paramString, X509NameEntryConverter paramX509NameEntryConverter)
  {
    return stringToBcX509Name(paramString, paramX509NameEntryConverter, getDefaultX509FieldOrder());
  }

  public static com.itrus.cert.X509Name stringToBcX509Name(String paramString, X509NameEntryConverter paramX509NameEntryConverter, Vector paramVector)
  {
    if (paramString == null)
      return null;
    Vector localVector1 = new Vector();
    Vector localVector2 = new Vector();
    X509NameTokenizer localX509NameTokenizer = new X509NameTokenizer(paramString);
    while (true)
    {
      if (!localX509NameTokenizer.hasMoreTokens())
        return getOrderedX509Name(new com.itrus.cert.X509Name(localVector1, localVector2, paramX509NameEntryConverter), paramVector, paramX509NameEntryConverter);
      String str1 = localX509NameTokenizer.nextToken();
      int i = str1.indexOf("=");
      if (i != -1)
      {
        String str2 = str1.substring(0, i).toLowerCase().trim();
        String str3 = str1.substring(i + 1);
        if (str3 != null)
          str3 = StringUtils.stripStart(str3, null);
        DERObjectIdentifier localDERObjectIdentifier = DnComponents.getOid(str2);
        if (localDERObjectIdentifier == null);
        try
        {
          localDERObjectIdentifier = new DERObjectIdentifier(str2);
          localVector1.add(localDERObjectIdentifier);
          localVector2.add(str3);
        }
        catch (IllegalArgumentException localIllegalArgumentException)
        {
        }
      }
    }
  }

  private static class BasicX509NameTokenizer
  {
    private StringBuffer buf = new StringBuffer();
    private int index;
    private String oid;

    public BasicX509NameTokenizer(String paramString)
    {
      this.oid = paramString;
      this.index = -1;
    }

    public boolean hasMoreTokens()
    {
      return this.index != this.oid.length();
    }

    public String nextToken()
    {
      if (this.index == this.oid.length())
        return null;
      int i = 1 + this.index;
      int j = 0;
      int k = 0;
      this.buf.setLength(0);
      if (i == this.oid.length())
      {
        label46: this.index = i;
        return this.buf.toString().trim();
      }
      char c = this.oid.charAt(i);
      if (c == '"')
        if (k == 0)
        {
          this.buf.append(c);
          if (j != 0)
          {
            j = 0;
            label99: k = 0;
          }
        }
      while (true)
      {
        i++;
        break;
        j = 1;
        break label99;
        this.buf.append(c);
        break label99;
        if ((k != 0) || (j != 0))
        {
          this.buf.append(c);
          k = 0;
        }
        else if (c == '\\')
        {
          this.buf.append(c);
          k = 1;
        }
        else
        {
          if ((c == ',') && (k == 0))
            break label46;
          this.buf.append(c);
        }
      }
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.util.CertUtils
 * JD-Core Version:    0.6.2
 */